<%--
  Created by IntelliJ IDEA.
  User: Gao
  Date: 2023/4/6
  Time: 19:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    用户名：<input id="nameId" type="text" name="name"/><span id="nameSpanId"></span><br/>
    密码：<input type="password" name="password"/><br/>
    <input type="button" value="添加">

    <script src="<%=request.getContextPath()%>/static/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
    <script>
        $(function() {
            $('#nameId').blur(function() {
                $.post(
                    '${pageContext.request.contextPath}/user?method=checkUserName',
                    {'name': $('#nameId').val()},
                    function(jsonResult) {
                        console.log(jsonResult)
                        if (jsonResult.code == 0) {//用户名可硬
                            $('#nameSpanId').html(jsonResult.msg);
                            $('#nameSpanId').css('color', 'green');
                        } else {
                            $('#nameSpanId').html(jsonResult.msg);
                            $('#nameSpanId').css('color', 'red');
                        }
                    },
                    'json'
                );
            });
        });
    </script>

</body>
</html>
